﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Othello_Game
{
    /// <summary>
    /// A normalize attribute implementing IAttributeNormalizedValues interface.
    /// Returns a score indicating the values of the board's positions.
    /// Also consider the ammount of opponent pieces flipped this turn.
    /// </summary>
    public class PositionValueAttribute : IAttributeNormalizedValues
    {
        /// <summary>
        /// Attribute value for values of the board's positions.
        /// </summary>
        /// <param name="actionList">A move to play</param>
        /// <returns></returns>
        public double GetAttributeValues(ActionList actionList)
        {
            // Normalized by 122
            return ((double) Value(actionList) / (double) 122);
        }

        /// <summary>
        /// Return a combined value of the game board's position value and the
        /// ammount of opponent's pieces flipped by the given ActionList
        /// </summary>
        /// <param name="actionList"></param>
        /// <returns></returns>
        private int Value(ActionList actionList)
        {
            // Take the board value of the position chosen.
            int counter = GeneralConsts.Instance.PositionsValues[actionList.Pos];

            // Add the number of all buttons to be flipped by this move
            for (int i = 0; i < actionList.Current; i++)
            {
                counter += actionList.Actions[i].Ammount;
            }
            return counter;
        }
    }
}
